package com.shhm.common.aspect;

import com.github.benmanes.caffeine.cache.Cache;
import com.shhm.common.context.PermsContextHolder;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.security.SecurityUser;
import com.shhm.common.entity.admin.SysRoleOperatePerms;
import com.shhm.common.mapper.SysRoleOperatePermsMapper;
import com.shhm.common.utils.LocalCacheUtil;
import com.shhm.common.utils.SysPermsUtil;
import jakarta.annotation.Resource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;


/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/13 下午2:05
 */
@Aspect
@Component
public class OperateStrAspect {
    @Around("execution(com.shhm.common.dto.response.AjaxResultPlus com.shhm.*.service.impl.*.pageList(..))")
    public Object addOperateStr(ProceedingJoinPoint joinPoint) throws Throwable {
        Object result = joinPoint.proceed();
        SysRoleOperatePerms permsObj = PermsContextHolder.getPermissions();
        if (Objects.isNull(permsObj)) return result;

        if (result instanceof AjaxResultPlus) {
            ((AjaxResultPlus) result).put("operateStr", permsObj.getOperateStr());
        }

        return result;
    }
}
